//
//  D_LocalMusicViewController.m
//  音悦咖
//
//  Created by dllo on 15/5/1.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "D_LocalMusicViewController.h"
#import "BaseHeader.h"
#import "D_MyMusicCollectionViewCell.h"
#import "D_AlerterUIview.h"
#import "D_BgImageViewController.h"
#import "MJRefresh.h"
#import "UMSocial.h"
#import "D_DataBase.h"
#import "L_Singleton.h"
#import "L_footPlaytabBar.h"
#import "D_MyMusic.h"
@interface D_LocalMusicViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout,UIAlertViewDelegate>
@property (nonatomic, retain) UICollectionView *collection;
@property (nonatomic, assign) NSInteger footerHight;
@property (nonatomic, assign) NSInteger sectionNum;
@property (nonatomic, assign) NSInteger tagNum;
@property (nonatomic, retain) NSMutableArray *url_list;
@property (nonatomic, retain) NSMutableDictionary *urlDic;
@property (nonatomic, retain) NSMutableArray *mv_list;
@property (nonatomic, retain) NSMutableDictionary *picDic;
@property (nonatomic, retain) NSMutableArray *firstArr;
@property (nonatomic, retain) NSMutableArray *secondArr;
@property (nonatomic, retain) NSMutableArray *thirdArr;
@property (nonatomic, retain) UIButton *button;



@end

@implementation D_LocalMusicViewController


- (void)dealloc
{
    [_num release];
    [_arr1 release];
    [_arr3 release];
    [_arr4 release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.firstArr = [NSMutableArray array];
    self.secondArr = [NSMutableArray array];
    self.thirdArr = [NSMutableArray array];
    self.url_list = [NSMutableArray array];
    self.urlDic = [NSMutableDictionary dictionary];
    self.mv_list = [NSMutableArray array];
    self.picDic = [NSMutableDictionary dictionary];
    

//    [self.url_list addObject:self.urlDic];
//    [self.mv_list addObject:self.picDic];
    
    if ([self.num isEqualToString:@"1"]) {
        self.titleLabel.text = @"本地歌曲";
    }else if ([self.num isEqualToString:@"2"]){
        self.titleLabel.text = @"最近播放";
    }else if([self.num isEqualToString:@"3"]){
        self.titleLabel.text = @"我喜欢";
    }else{
         self.titleLabel.text = @"我的收藏";
    }
    self.view.backgroundColor = [UIColor whiteColor];
    // 背景图片
    UIImageView *backImg = [[UIImageView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    backImg.image = [UIImage imageNamed:@"musicbg.jpg"];
    backImg.alpha = 0.8;
    [self.view addSubview:backImg];
    [backImg release];
    
    if ([self.num isEqualToString:@"3"]) {
        
        D_DataBase *data = [[D_DataBase alloc] init];
        [data openDB];
        self.arr3 = [NSMutableArray array];
        self.arr3 = [data selectInfor];
        
    }else if ([self.num isEqualToString:@"1"] || [self.num isEqualToString:@"2"]) {
        
        D_DataBase *data = [[D_DataBase alloc] init];
        [data openDB];
        self.arr1 = [NSMutableArray array];
        self.arr1 = [data selectLocal];
        
        
        
    }else if([self.num isEqualToString:@"4"]){
        D_DataBase *data = [[D_DataBase alloc] init];
        [data openDB];
        self.arr4 = [NSMutableArray array];
        self.arr4 = [data selectCollect];
        

    }
    
    // collection
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(SCREEN_WIDTH - 20 , 50);
//    layout.minimumLineSpacing = 30;
    
    layout.sectionInset = UIEdgeInsetsMake(20, 0, 0, 0);
#pragma mark - footer
//    layout.headerReferenceSize = CGSizeMake(355, 100);
//    layout.footerReferenceSize = CGSizeMake(300, 50);
    
    self.collection = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 100) collectionViewLayout:layout];
    self.collection.backgroundColor = [UIColor clearColor];
    self.collection.delegate = self;
    self.collection.dataSource = self;
    self.collection.contentInset = UIEdgeInsetsMake(20, 0, 20, 0);
    [self.view addSubview:self.collection];
#pragma mark - 注册重用池
    [self.collection registerClass:[D_MyMusicCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    [self.collection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
    [self.collection registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header"];
    
    
#pragma mark - 刷新
//    [self.collection addHeaderWithTarget:self action:@selector(headRefresh)];
//    [self.collection addFooterWithTarget:self action:@selector(footRefresh)];
    
    [self.collection release];
    [layout release];
    
    
}
//// 进来刷新
//- (void)viewWillAppear:(BOOL)animated
//{
//    [self.collection headerBeginRefreshing];
//    [self.collection headerEndRefreshing];
//}
//// 头部结束刷新
//- (void)headRefresh
//{
//    [self.collection headerEndRefreshing];
//}
//
//- (void)footRefresh
//{
//    [self.collection footerEndRefreshing];
//}

#pragma mark - 头部大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return CGSizeMake(0, 0);
    }
    return CGSizeMake(0, 0);
}

#pragma mark - 尾部方法协议
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
{
    if (section == self.sectionNum) {
        return CGSizeMake(SCREEN_WIDTH, self.footerHight);
    }
    return CGSizeMake(0, 0);
 
}
#pragma mark - footer/header 协议方法
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if (kind == UICollectionElementKindSectionHeader) {
        UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
        header.backgroundColor = [UIColor grayColor];
        [header.layer setCornerRadius:20];
        header.alpha = 0.6;
        
        return header;
    }
    
    
    if (kind == UICollectionElementKindSectionFooter) {
        UICollectionReusableView *footer = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"footer" forIndexPath:indexPath];
        footer.backgroundColor = [UIColor clearColor];
//        footer.alpha = 0.3;
//        [footer.layer setCornerRadius:10];
        
        // 分享按钮
        UIButton *share = [UIButton buttonWithType:UIButtonTypeSystem];
        share.frame = CGRectMake(SCREEN_WIDTH * 0.12, 20, 30, 30);
        share.backgroundColor = [UIColor clearColor];
        [share setImage:[[UIImage imageNamed:@"share"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
        [share addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
        share.tag = indexPath.section;
        UILabel *shareLable = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.12, 55, 50, 20)];
        shareLable.text = @"分享";
        shareLable.font = [UIFont fontWithName:nil size:14];
        [footer addSubview:shareLable];
        [footer addSubview:share];
        [shareLable release];
      
        // 我喜欢按钮
        UIButton *myLovew = [UIButton buttonWithType:UIButtonTypeSystem];
        myLovew.frame = CGRectMake(SCREEN_WIDTH * 0.32, 20, 30, 30);
        myLovew.backgroundColor = [UIColor clearColor];
        [myLovew setImage:[[UIImage imageNamed:@"mylove"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
        [myLovew addTarget:self action:@selector(myLoveAction:) forControlEvents:UIControlEventTouchUpInside];
        UILabel *myLovewLable = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.3, 55, 50, 20)];
        myLovewLable.text = @"我喜欢";
        myLovew.tag = indexPath.section;
        myLovewLable.font = [UIFont fontWithName:nil size:14];
        [footer addSubview:myLovewLable];
        [footer addSubview:myLovew];
        [myLovewLable release];
        
        // 收藏
        UIButton *collect = [UIButton buttonWithType:UIButtonTypeSystem];
        collect.frame = CGRectMake(SCREEN_WIDTH * 0.53, 20, 30, 30);
        collect.backgroundColor = [UIColor clearColor];
        [collect setImage:[[UIImage imageNamed:@"save"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
        [collect addTarget:self action:@selector(collectAction:) forControlEvents:UIControlEventTouchUpInside];
        UILabel *collectLable = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.53, 55, 50, 20)];
        collectLable.text = @"收藏";
        collect.tag = indexPath.section;
        collectLable.font = [UIFont fontWithName:nil size:14];
        [footer addSubview:collectLable];
        [footer addSubview:collect];
        [collectLable release];
        
        // 删除
        UIButton *delete = [UIButton buttonWithType:UIButtonTypeSystem];
        delete.frame = CGRectMake(SCREEN_WIDTH * 0.74, 20, 30, 30);
        delete.backgroundColor = [UIColor clearColor];
        [delete setImage:[[UIImage imageNamed:@"deletemusic"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]forState:UIControlStateNormal];
        [delete addTarget:self action:@selector(deleteAction:) forControlEvents:UIControlEventTouchUpInside];
        delete.tag = indexPath.section;
        UILabel *deleteLable = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH * 0.74, 55, 50, 20)];
        deleteLable.text = @"删除";
        deleteLable.font = [UIFont fontWithName:nil size:14];
        [footer addSubview:deleteLable];
        [footer addSubview:delete];
        [deleteLable release];
        
        return footer;
    }
    return nil;
}

#pragma mark - 分享
- (void)shareAction:(UIButton *)button
{
//    [D_AlerterUIview showAlert:@"分享成功!"];
    if ([self.num isEqualToString:@"1"] || [self.num isEqualToString:@"2"]) {
        
        NSString *url = [NSString stringWithFormat:@"%@",[self.arr1[button.tag]url]];
        NSString *song = [NSString stringWithFormat:@"%@",[self.arr1[button.tag] song_name]];
        NSString *str = [NSString stringWithFormat:@"请输入要分享的文字.......%@%@",url,song];
    [UMSocialSnsService presentSnsIconSheetView:self appKey:SDK_KEY shareText:str shareImage:[UIImage imageNamed:@"lloo"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToQzone,UMShareToQQ,nil] delegate:nil];
    
    [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatTimeline]];
    
    }else if ([self.num isEqualToString:@"3"]){
        
        NSString *url = [NSString stringWithFormat:@"%@",[self.arr3[button.tag]url]];
        NSString *song = [NSString stringWithFormat:@"%@",[self.arr3[button.tag] song_name]];
        NSString *str = [NSString stringWithFormat:@"请输入要分享的文字.......%@%@",url,song];
        [UMSocialSnsService presentSnsIconSheetView:self appKey:SDK_KEY shareText:str shareImage:[UIImage imageNamed:@"lloo"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToQzone,UMShareToQQ,nil] delegate:nil];
        
        [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatTimeline]];

    }else if ([self.num isEqualToString:@"4"])
    {
        NSString *url = [NSString stringWithFormat:@"%@",[self.arr4[button.tag]url]];
        NSString *song = [NSString stringWithFormat:@"%@",[self.arr4[button.tag] song_name]];
        NSString *str = [NSString stringWithFormat:@"请输入要分享的文字.......%@%@",url,song];
        [UMSocialSnsService presentSnsIconSheetView:self appKey:SDK_KEY shareText:str shareImage:[UIImage imageNamed:@"lloo"] shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToTencent,UMShareToRenren,UMShareToQzone,UMShareToQQ,nil] delegate:nil];
        
        [UMSocialConfig hiddenNotInstallPlatforms:@[UMShareToQQ,UMShareToQzone,UMShareToWechatTimeline]];
    }
    
}

#pragma mark - 我喜欢
- (void)myLoveAction:(UIButton *)button
{
    NSInteger num = button.tag;
    
    D_DataBase *data = [[D_DataBase alloc] init];
    [data openDB];
    if ([self.num isEqualToString:@"1"] || [self.num isEqualToString:@"2"]) {
    NSArray *localArr = [NSArray array];
    localArr = [data selectInfor];
    NSInteger tempNum = 0;
    for (NSInteger i = 0; i < localArr.count ; i++) {
        if ([[localArr[i] song_name] isEqualToString:[self.arr1[num] song_name]]) {
            tempNum = 2;
        }
    }
        if (tempNum == 0) {
            
            D_MyMusic *myMusic = [[D_MyMusic alloc] init];
            myMusic.singer_name = [self.arr1[num] singer_name];
            myMusic.song_name = [self.arr1[num] song_name];
            myMusic.url = [[[self.firstArr[num] url_list] firstObject] objectForKey:@"url"];
        
            [data openDB];
            [data insertInforMyMusic:myMusic];
            [D_AlerterUIview showAlert:@"添加成功!"];
        }else{
            [D_AlerterUIview showAlert:@"已经添加!"];
        }
    
    }
    if ([self.num isEqualToString:@"3"]) {
        [D_AlerterUIview showAlert:@"已经添加!"];
    }
    
    
    if ([self.num isEqualToString:@"4"]) {
        NSArray *localArr = [NSArray array];
        localArr = [data selectInfor];
        NSInteger tempNum = 0;
        for (NSInteger i = 0; i < localArr.count ; i++) {
            if ([[localArr[i] song_name] isEqualToString:[self.arr4[num] song_name]]) {
                tempNum = 2;
            }
        }
        if (tempNum == 0) {
           
            D_MyMusic *myMusic = [[D_MyMusic alloc] init];
            myMusic.singer_name = [self.arr4[num] singer_name];
            myMusic.song_name = [self.arr4[num] song_name];
            myMusic.url = [[[self.thirdArr[num] url_list]firstObject] objectForKey:@"url"];
            [data openDB];
            [data insertInforMyMusic:myMusic];
            [D_AlerterUIview showAlert:@"添加成功!"];
        }else{
            [D_AlerterUIview showAlert:@"已经添加!"];
        }
    }
    
    
    
}
#pragma mark - 收藏
- (void)collectAction:(UIButton *)button
{
    NSInteger num = button.tag;
    
    D_DataBase *data = [[D_DataBase alloc] init];
    [data openDB];
    if ([self.num isEqualToString:@"1"] || [self.num isEqualToString:@"2"]) {
        NSArray *localArr = [NSArray array];
        localArr = [data selectCollect];
        NSInteger tempNum = 0;
        for (NSInteger i = 0; i < localArr.count ; i++) {
            if ([[localArr[i] song_name] isEqualToString:[self.arr1[num] song_name]]) {
                tempNum = 2;
            }
        }
        if (tempNum == 0) {
            
            D_MyMusic *myMusic = [[D_MyMusic alloc] init];
            myMusic.singer_name = [self.arr1[num] singer_name];
            myMusic.song_name = [self.arr1[num] song_name];
            myMusic.url = [[[self.firstArr[num] url_list] firstObject] objectForKey:@"url"];
            [data openDB];
            [data insertMyCollect:myMusic];
            [D_AlerterUIview showAlert:@"收藏成功!"];
        }else{
            [D_AlerterUIview showAlert:@"已经收藏!"];
        }
        
    }
    
    if ([self.num isEqualToString:@"4"]) {
        [D_AlerterUIview showAlert:@"已经收藏!"];
    }
    
    if ([self.num isEqualToString:@"3"]) {
        
        NSArray *localArr = [NSArray array];
        localArr = [data selectCollect];
        NSInteger tempNum = 0;
        for (NSInteger i = 0; i < localArr.count ; i++) {
            if ([[localArr[i] song_name] isEqualToString:[self.arr3[num] song_name]]) {
                tempNum = 2;
            }
        }
        if (tempNum == 0) {
            
            D_MyMusic *myMusic = [[D_MyMusic alloc] init];
            myMusic.singer_name = [self.arr3[num] singer_name];
            myMusic.song_name = [self.arr3[num] song_name];
            myMusic.url = [[[self.secondArr[num] url_list]firstObject] objectForKey:@"url"];
            [data openDB];
            [data insertMyCollect:myMusic];
            [D_AlerterUIview showAlert:@"收藏成功!"];
        }else{
            [D_AlerterUIview showAlert:@"已经收藏!"];
        }
    }
    
    
}
#pragma mark - 删除
- (void)deleteAction:(UIButton *)button
{
    NSInteger aa = button.tag;
    D_DataBase *data = [[D_DataBase alloc] init];
    [data openDB];
   [D_AlerterUIview showAlert:@"删除成功!"];
    
    if ([self.num isEqualToString:@"3"]) {
         [data deleteInforWithNum:[self.arr3[aa] song_name]];
        [self.arr3 removeObjectAtIndex:aa];
    }
    if([self.num isEqualToString:@"1"] || [self.num isEqualToString:@"2"]){
        [data deleteLocal:[self.arr1[aa] song_name]];
        [self.arr1 removeObjectAtIndex:aa];
    }
    
    if([self.num isEqualToString:@"4"]){
        [data deleteCollection:[self.arr4[aa] song_name]];
         [self.arr4 removeObjectAtIndex:aa];
    }

    
    [self.collection reloadData];
   
 
}


#pragma mark - collection协议方法
// section 个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    if ([self.num isEqualToString:@"3"]) {
        return self.arr3.count;
    }else if([self.num isEqualToString:@"1"]){
        return self.arr1.count;
    } else if([self.num isEqualToString:@"2"]){
         return self.arr1.count;
    } else if([self.num isEqualToString:@"4"]){
        return self.arr4.count;
    }
    return 20;
}
// item个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 1;
}
// cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    D_MyMusicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor grayColor];
    cell.alpha = 0.6;
    [cell.layer setBorderWidth:2];
    [cell.layer setBorderColor:[UIColor grayColor].CGColor];
//        [cell.layer setCornerRadius:10];
    
    if ([self.num isEqualToString:@"3"]) {
        
        PlayerModel *playModel = [[PlayerModel alloc] init];
//        [self.urlDic setValue:[self.arr3[indexPath.section] url] forKey:@"url"];
//        
//        [self.urlDic setValue:[self.arr3[indexPath.section] duration_time] forKey:@"duration"];
//        [self.picDic setValue:[self.arr3[indexPath.section] pic_url] forKey:@"pic_url"];
        
        NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
        NSMutableDictionary *picDic = [NSMutableDictionary dictionary];
        
        [tempDic setObject:[self.arr3[indexPath.section] url] forKey:@"url"];
        [tempDic setObject:[self.arr3[indexPath.section] duration_time] forKey:@"duration"];
        [picDic setObject:[self.arr3[indexPath.section] pic_url] forKey:@"pic_url"];
        [self.url_list removeAllObjects];
        [self.url_list addObject:tempDic];
        
        playModel.song_name = [self.arr3[indexPath.section] song_name];
        playModel.singer_name = [self.arr3[indexPath.section] singer_name];
        playModel.song_id = [self.arr3[indexPath.section] song_id];
        
        playModel.url_list = [NSArray arrayWithArray:self.url_list];
        playModel.mv_list = [NSArray arrayWithArray:self.mv_list];
        
        cell.singerLable.text = [self.arr3[indexPath.section] singer_name];
        cell.songLable.text = [self.arr3[indexPath.section] song_name];
        
        
        [self.secondArr addObject:playModel];
        
        [playModel release];
    }else if([self.num isEqualToString:@"1"] ||[self.num isEqualToString:@"2"] ){
      
#warning adsfasdfasdf
        PlayerModel *playModel = [[PlayerModel alloc] init];
        
        NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
        NSMutableDictionary *picDic = [NSMutableDictionary dictionary];
        
        [tempDic setObject:[self.arr1[indexPath.section] url] forKey:@"url"];
        [tempDic setObject:[self.arr1[indexPath.section] duration_time] forKey:@"duration"];
        [picDic setObject:[self.arr1[indexPath.section] pic_url] forKey:@"pic_url"];
        [self.url_list removeAllObjects];
        [self.url_list addObject:tempDic];
        
        playModel.song_name = [self.arr1[indexPath.section] song_name];
        playModel.singer_name = [self.arr1[indexPath.section] singer_name];
         playModel.song_id = [self.arr1[indexPath.section] song_id];

        playModel.url_list = [NSArray arrayWithArray:self.url_list];
        playModel.mv_list = [NSArray arrayWithArray:self.mv_list];
        
        cell.singerLable.text = [self.arr1[indexPath.section] singer_name];
        cell.songLable.text = [self.arr1[indexPath.section] song_name];
        
        [self.firstArr addObject:playModel];
        
        
        [playModel release];
        
    }else if([self.num isEqualToString:@"4"]){
        
//        PlayerModel *playModel = [[PlayerModel alloc] init];
//        
//        NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
//        NSMutableDictionary *picDic = [NSMutableDictionary dictionary];
//        
//        [tempDic setObject:[self.arr4[indexPath.section] url] forKey:@"url"];
//        [tempDic setObject:[self.arr4[indexPath.section] duration_time] forKey:@"duration"];
//        [picDic setObject:[self.arr4[indexPath.section] pic_url] forKey:@"pic_url"];
//        [self.url_list removeAllObjects];
//        [self.url_list addObject:tempDic];
//        
//        playModel.song_name = [self.arr4[indexPath.section] song_name];
//        playModel.singer_name = [self.arr4[indexPath.section] singer_name];
//        playModel.song_id = [self.arr4[indexPath.section] song_id];
//        
//        playModel.url_list = [NSArray arrayWithArray:self.url_list];
//        playModel.mv_list = [NSArray arrayWithArray:self.mv_list];
//        
//        cell.singerLable.text = [self.arr4[indexPath.section] singer_name];
//        cell.songLable.text = [self.arr4[indexPath.section] song_name];
//        
//        [self.thirdArr addObject:playModel];
//        
//        [playModel release];
        PlayerModel *playModel = [[PlayerModel alloc] init];
        
        NSMutableDictionary *tempDic = [NSMutableDictionary dictionary];
        NSMutableDictionary *picDic = [NSMutableDictionary dictionary];
        
        [tempDic setObject:[self.arr4[indexPath.section] url] forKey:@"url"];
        [tempDic setObject:[self.arr4[indexPath.section] duration_time] forKey:@"duration"];
        [picDic setObject:[self.arr4[indexPath.section] pic_url] forKey:@"pic_url"];
        [self.url_list removeAllObjects];
        [self.url_list addObject:tempDic];
        
        playModel.song_name = [self.arr4[indexPath.section] song_name];
        playModel.singer_name = [self.arr4[indexPath.section] singer_name];
        playModel.song_id = [self.arr4[indexPath.section] song_id];
        
        playModel.url_list = [NSArray arrayWithArray:self.url_list];
        playModel.mv_list = [NSArray arrayWithArray:self.mv_list];
        
        cell.singerLable.text = [self.arr4[indexPath.section] singer_name];
        cell.songLable.text = [self.arr4[indexPath.section] song_name];
        
        [self.thirdArr addObject:playModel];
        
        [playModel release];

    }

#pragma mark - 尾部button
    // 控制尾部buuton
     self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    self.button.frame = CGRectMake(SCREEN_WIDTH * 0.75, 20, 20, 20);
    self.button.backgroundColor = [UIColor clearColor];
    self.button.tag = indexPath.section;
    [self.button setBackgroundImage:[UIImage imageNamed:@"footerdown"] forState:UIControlStateNormal];
    
    [self.button addTarget:self action:@selector(myFooterAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [cell addSubview:self.button];
    

    return  cell;
}

// item选择方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
     L_Singleton *single = [L_Singleton shareManager];
    L_footPlaytabBar *footTabBar = [L_footPlaytabBar shareTabBar];
    // 定时器开启
    [footTabBar.time setFireDate:[NSDate distantPast]];
    
    
    if ([self.num isEqualToString:@"1"] || [self.num isEqualToString:@"2"]) {
       
        
        // 传值
         single.song_id = [self.firstArr[indexPath.section] song_id];
        single.index = indexPath.section;
        
 
        if (self.firstArr.count == 0) {
        }else {
            
        // 添加到单例数组中
        if (single.array == nil) {
            
            single.array = [NSMutableArray arrayWithArray:self.firstArr];
            
            NSString *url = (NSString *)[self.arr1[indexPath.section] url];
            
            
            [single playWithUrl:url];
            single.playUrl = url;
            single.state = @"playing";
            single.index = indexPath.section;
            
            
            footTabBar.footPlayView.songName.text = [self.firstArr[indexPath.section] song_name];
            footTabBar.footPlayView.songerName.text = [self.firstArr[indexPath.section] singer_name];
            [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
            [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
            
            
        } else if ([single.array firstObject] != [self.firstArr firstObject]) {
            
//            single.array = [NSMutableArray array];
//            for (PlayerModel *play in self.firstArr) {
//                [single.array addObject:play];
//                
//            }
            
            single.array = [NSMutableArray arrayWithArray:self.firstArr];
            
            
            NSString *url = (NSString *)[self.arr1[indexPath.section] url];
            
        
            [single playWithUrl:url];
            self.single.playUrl = url;
            single.state = @"playing";
            single.index = indexPath.section;
            footTabBar.footPlayView.songName.text = [self.firstArr[indexPath.section] song_name];
            footTabBar.footPlayView.songerName.text = [self.firstArr[indexPath.section] singer_name];
            [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
            [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
        } else {
            
            
            single.song_id = [single.array[indexPath.section] song_id];
            NSString *url = (NSString *)[self.arr1[indexPath.section] url];
            
            
            
            [single playWithUrl:url];
            self.single.playUrl = url;
            single.state = @"playing";
            single.index = indexPath.section;
            footTabBar.footPlayView.songName.text = [self.firstArr[indexPath.section] song_name];
            footTabBar.footPlayView.songerName.text = [self.firstArr[indexPath.section] singer_name];
            [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
            [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
        }

        }
    }else if([self.num isEqualToString:@"3"]){
        
        // 传值
        single.song_id = [self.arr3[indexPath.section] song_id];
        single.index = indexPath.section;
    
        if (self.secondArr.count == 0) {
        
        } else {
            
        // 添加到单例数组中
        if (single.array == nil) {

            single.array = [NSMutableArray arrayWithArray:self.secondArr];
            
            NSString *url = (NSString *)[self.arr3[indexPath.section] url];
            [single playWithUrl:url];
            self.single.playUrl = url;
            single.state = @"playing";
            single.index = indexPath.section;
            
            
            footTabBar.footPlayView.songName.text = [self.secondArr[indexPath.section] song_name];
            footTabBar.footPlayView.songerName.text = [self.secondArr[indexPath.section] singer_name];
            [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
            [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
            
            
        } else if ([single.array firstObject] != [self.secondArr firstObject]) {
            single.array = [NSMutableArray array];

            single.array = [NSMutableArray arrayWithArray:self.secondArr];
            
           NSString *url = (NSString *)[self.arr3[indexPath.section] url];
            
            [single playWithUrl:url];
            self.single.playUrl = url;
            single.state = @"playing";
            single.index = indexPath.section;
            footTabBar.footPlayView.songName.text = [self.secondArr[indexPath.section] song_name];
            footTabBar.footPlayView.songerName.text = [self.secondArr[indexPath.section] singer_name];
            [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
            [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
        } else {
            single.song_id = [single.array[indexPath.section] song_id];
           NSString *url = (NSString *)[self.arr3[indexPath.section] url];
            [single playWithUrl:url];
            self.single.playUrl = url;
            single.state = @"playing";
            single.index = indexPath.section;
            footTabBar.footPlayView.songName.text = [self.secondArr[indexPath.section] song_name];
            footTabBar.footPlayView.songerName.text = [self.secondArr[indexPath.section] singer_name];
            [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
            [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
        }
        }
        
    
    }else if ([self.num isEqualToString:@"4"]){
   
        // 传值
        single.song_id = [self.arr4[indexPath.section] song_id];
        single.index = indexPath.section;
        
        if (self.thirdArr.count == 0) {
            
        } else {
            
            // 添加到单例数组中
            if (single.array == nil) {
                
                single.array = [NSMutableArray arrayWithArray:self.thirdArr];
                
                NSString *url = (NSString *)[self.arr4[indexPath.section] url];
                [single playWithUrl:url];
                self.single.playUrl = url;
                single.state = @"playing";
                single.index = indexPath.section;
                
                
                footTabBar.footPlayView.songName.text = [self.thirdArr[indexPath.section] song_name];
                footTabBar.footPlayView.songerName.text = [self.thirdArr[indexPath.section] singer_name];
                [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
                [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
                
                
            } else if ([single.array firstObject] != [self.thirdArr firstObject]) {

                single.array = [NSMutableArray array];
                single.array = [NSMutableArray arrayWithArray:self.thirdArr];
                
                NSString *url = (NSString *)[self.arr4[indexPath.section] url];
                
                [single playWithUrl:url];
                self.single.playUrl = url;
                single.state = @"playing";
                single.index = indexPath.section;
                footTabBar.footPlayView.songName.text = [self.thirdArr[indexPath.section] song_name];
                footTabBar.footPlayView.songerName.text = [self.thirdArr[indexPath.section] singer_name];
                [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
                [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
            } else {
                single.song_id = [single.array[indexPath.section] song_id];
                NSString *url = (NSString *)[self.arr4[indexPath.section] url];
                [single playWithUrl:url];
                self.single.playUrl = url;
                single.state = @"playing";
                single.index = indexPath.section;
                footTabBar.footPlayView.songName.text = [self.thirdArr[indexPath.section] song_name];
                footTabBar.footPlayView.songerName.text = [self.thirdArr[indexPath.section] singer_name];
                [footTabBar.footPlayView.mainImage setImageWithURL:[NSURL URLWithString:[[[single.array[indexPath.section] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"playCard.jpg"]];
                [footTabBar.footPlayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
            }
        }
    }

}

#pragma mark - 按钮显示footer
- (void)myFooterAction:(UIButton *)button
{
//    if (self.Bstart == YES) {
//        [self.button setBackgroundImage:[UIImage imageNamed:@"footerup"] forState:UIControlStateNormal];
//    }else{
//        [self.button setBackgroundImage:[UIImage imageNamed:@"footerdown"] forState:UIControlStateNormal];
//
//    }
    if (button.tag == self.tagNum) {
        self.footerHight = 0;
        self.tagNum = 1111110;
    }else{
        self.footerHight = 80;
        self.tagNum = button.tag;
    }
    self.sectionNum = button.tag;
    [self.collection reloadData];
    
}

// 返回按钮
- (void)backAction
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
